package com.cb.staservice.schedule;

import com.cb.staservice.service.StatisticsDailyService;
import com.cb.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时任务
 *
 * @author cb
 * @version 1.0
 * @date 2020/7/1 15:36
 */
@Component
public class ScheduledTask {

    private final StatisticsDailyService dailyService;

    @Autowired
    public ScheduledTask(StatisticsDailyService dailyService) {
        this.dailyService = dailyService;
    }

    /**
     * 每天凌晨1点执行一次任务 , 统计注册人数
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void task(){
        dailyService.registerCount(
                DateUtil.formatDate(
                        DateUtil.addDays(new Date(), -1)
                )
        );
    }

}
